package com.dk.controller;

import com.dk.pojo.TabCategory;
import com.dk.pojo.TabSeller;
import com.dk.service.TabSellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tabSeller")
public class TabSellerController {
    @Autowired
    private TabSellService tabSellService;

    @RequestMapping("toShow")
    public String toShow(){
        return "tabSeller/show";
    }
    @RequestMapping("getInfo")
    @ResponseBody
    public List<TabSeller> getInfo(String sname){
        List<TabSeller> result = tabSellService.getInfo(sname);
        return result;
    }
    @RequestMapping("toAdd")
    public String toAdd(){
        return "tabSeller/add";
    }
    @RequestMapping("increase")
    @ResponseBody
    public boolean insertInfo(TabSeller tabSeller){
        return tabSellService.insert(tabSeller) > 0;
    }
    @RequestMapping("toUpdate/{id}")
    public String toUpdate(@PathVariable("id")Integer cid, Model model){
        TabSeller tabSeller = tabSellService.selectById(cid);
        model.addAttribute("tabSeller",tabSeller);
        return "tabSeller/update";
    }
    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(TabSeller tabSeller){
        return tabSellService.updateInfo(tabSeller) > 0;
    }
    @RequestMapping("deleteById")
    @ResponseBody
    public boolean deleteById(Integer cid){
        return tabSellService.deleteById(cid) > 0;
    }
}
